﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mNC.Calculate
{
    public class AL_TAPP
    {
        /// <summary>
        /// TAPP_HEAD
        /// </summary>
        /// <param name="TOOL_NO">刀具号</param>
        /// <param name="TOOL_DIA">刀具直径</param>
        /// <param name="NOSECODE">机头代码</param>
        /// <param name="ROTATE_SPEED">转速</param>
        /// <param name="FACE_HEIGHT">安全高度</param>
        /// <param name="COORD_X">X坐标</param>
        /// <param name="COORD_Y">Y坐标</param>
        /// <param name="COMPENSATION_NO">刀补号</param>
        /// <returns></returns>
        public static string GET_TAPP_HEAD(string TOOL_NO, string TOOL_DIA, string NOSECODE, string ROTATE_SPEED, string FACE_HEIGHT, string COORD_X, string COORD_Y, string COMPENSATION_NO)
        {
            StringBuilder str = new StringBuilder("(TAPP_HEAD)");
            str.Append("\r\n");
            str.Append("G00G91G28Z0.");
            str.Append("\r\n");
            str.Append("G00G91G28Y0.");
            str.Append("\r\n");
            str.Append("(TOOL_" + TOOL_NO + "_DIA_" + TOOL_DIA + ")");
            str.Append("\r\n");
            str.Append("M06" + TOOL_NO + "");
            str.Append("\r\n");
            str.Append("G00G90" + NOSECODE + "S" + ROTATE_SPEED + "M03");
            str.Append("\r\n");
            str.Append("X" + COORD_X + "Y-" + COORD_Y + "");
            str.Append("\r\n");
            str.Append("G00G43" + COMPENSATION_NO + "Z" + FACE_HEIGHT + "M08");
            str.Append("\r\n");
            str.Append("(TAPP_HEAD)");
            str.Append("\r\n");
            str.Append("");
            str.Append("\r\n");
            return str.ToString();
        }

        /// <summary>
        /// TAPP_END
        /// </summary>
        /// <param name="FEATURE_TYPE">特征类型</param>
        /// <returns></returns>
        public static string GET_AL_TAPP_END(string FEATURE_TYPE)
        {
            StringBuilder str = new StringBuilder("(" + FEATURE_TYPE + "_END)");
            str.Append("\r\n");
            str.Append("G80");
            str.Append("\r\n");
            str.Append("(" + FEATURE_TYPE + "_END)");
            str.Append("\r\n");
            str.Append("");
            str.Append("\r\n");
            return str.ToString();
        }

        /// <summary>
        /// TAPP_CYCLE
        /// </summary>
        /// <param name="dt">中间表</param>
        /// <param name="INITIAL_HEIGHT">初始高度</param>
        /// <param name="PROCESS_DEPTH">加工深度</param>
        /// <returns></returns>
        public static string GET_AL_TAPP_CYCLE(DataTable dt, string INITIAL_HEIGHT, string PROCESS_DEPTH)
        {
            string strlist = "";
            if (dt.Rows.Count > 0)
            {
                string COORD_X = Convert.ToDouble(dt.Rows[0]["COORD_X"]).ToString("0.00");
                string COORD_Y = dt.Rows[0]["COORD_Y"].ToString();
                string FEED_SPEED_V = dt.Rows[0]["FEED_SPEED_V"].ToString().Length > 0 ? Convert.ToDouble(dt.Rows[0]["FEED_SPEED_V"].ToString()).ToString("0.00") : "";
                StringBuilder str = new StringBuilder("(TAPP_CYCLE)");
                str.Append("\r\n");
                str.Append("G98G84X" + COORD_X + "Y-" + COORD_Y + "Z" + PROCESS_DEPTH + "R" + INITIAL_HEIGHT + "F" + FEED_SPEED_V + "");
                str.Append("\r\n");
                for (int i = 1; i < dt.Rows.Count; i++)
                {

                    str.Append("X" + Convert.ToDouble(dt.Rows[i]["COORD_X"]).ToString("0.00") + "Y-" + dt.Rows[i]["COORD_Y"].ToString() + "");
                    str.Append("\r\n");
                }
                str.Append("(TAPP_CYCLE)");
                str.Append("\r\n");
                str.Append("");
                str.Append("\r\n");
                strlist = str.ToString();
            }

            return strlist;
        }
    }
}
